package com.softline.documentsmall.controller;

import com.alibaba.fastjson.JSONObject;
import com.softline.documentsmall.ret.BusinessErrorEnum;
import com.softline.documentsmall.ret.ReturnVO;
import com.softline.documentsmall.ret.ReturnVOUtils;
import com.softline.documentsmall.service.LogAnalyseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wph
 * @Date 2021/1/21 16:37
 */
@Api(value = "行为分析相关接口", tags = {"行为分析相关接口"})
@RestController
@RequestMapping("/log")
@CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
public class LogAnalyseController {

    @Autowired
    private LogAnalyseService logAnalyseService;

    /**
     * 根据语言,用户ID查询5大图表数据
     *
     * @param type   术语类型
     * @param userId 用户id
     * @return
     */
    @ApiOperation(value = "行为分析5大图表查询", notes = "行为分析5大图表查询")
    @GetMapping(value = "/selectList")
    public ReturnVO selectList(@RequestParam(name = "type", defaultValue = "cn") String type, String userId) {
        JSONObject resultObject = logAnalyseService.selectList(type, userId);
        if (resultObject != null && resultObject.size() != 0) {
            return ReturnVOUtils.success(resultObject);
        } else {
            return ReturnVOUtils.businessFail(BusinessErrorEnum.FAIL);
        }
    }
    /**
     * 根据语种查询行为分析页面知识图谱
     */
    @ApiOperation(value = "根据语种查询行为分析知识图谱", notes = "根据语种查询行为分析知识图谱")
    @GetMapping(value = "/selectKnowledge")
    public ReturnVO selectKnowledge(@RequestParam(name = "type", defaultValue = "cn") String type, String userId) {
        JSONObject resultObject = logAnalyseService.selectKnowledge(type, userId);
        if (resultObject != null && resultObject.size() != 0) {
            return ReturnVOUtils.success(resultObject);
        } else {
            return ReturnVOUtils.businessFail(BusinessErrorEnum.FAIL);
        }
    }
}
